package com.yun.blog.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yun.blog.bean.Star;
import com.yun.blog.bean.dto.StarBlogDto;
import com.yun.blog.dao.StarMapper;
import com.yun.blog.service.StarService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class StarServiceImpl
        extends ServiceImpl<StarMapper, Star>
        implements StarService {

    @Resource
    StarMapper starMapper;

    @Override
    public boolean isStar(Integer userId, Integer blogId) {
        LambdaQueryWrapper<Star> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(Star::getUserId, userId).eq(Star::getBlogId, blogId);
        Star star = starMapper.selectOne(queryWrapper);
        return star != null;
    }

    @Override
    public <P extends IPage<StarBlogDto>> P getStarBlog(P page, Integer userId) {
        return starMapper.getStarBlog(page, userId);
    }
}
